

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Vector;

public class boxPrinter {

	public static void printtoSVG(Vector<pieceCoordinate> pieceorder, 
			double width, String orderFile, double result) {
		//for SVG
		try {
			double offset = 1;
			FileWriter f = new FileWriter(orderFile+".svg");
			PrintWriter buffprint = new PrintWriter(f);
			buffprint.println("<?xml version=\"1.0\" standalone=\"no\"?>");

			buffprint.println("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
			buffprint.println("\"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">");

			buffprint.println("<svg viewBox=\"0 0 " + (width+(offset*2)) + " " + (result+(offset*2)) + "\" width=\"100%\" height=\"100%\" version=\"1.1\"");
			buffprint.println("xmlns=\"http://www.w3.org/2000/svg\">");
			buffprint.println();
			buffprint.println("<rect x=\"" + offset + "\" y=\"" + offset 
					+ "\" width=\"" + width + "\" height=\"" + result + "\"");
			buffprint.println("style=\"fill:rgb(255,255,255);");
			buffprint.println("stroke-width:0.1;stroke:rgb(0,0,0)\"/>");
			buffprint.println();
			for (int y = 0; y < pieceorder.size(); y++) {
				pieceCoordinate t = pieceorder.elementAt(y);
				//String colour = t.colour+ ","+t.colour+ ","+t.colour;
				int mod = 12;
				String colour = "";
				if (y % mod == 0) {
					colour = "255,0,0";
				} else if (y % mod == 1) {
					colour = "0,255,0";
				} else if (y % mod == 2) {
					colour = "0,0,255";
				} else if (y % mod == 3) {
					colour = "0,255,255";
				} else if (y % mod == 4) {
					colour = "255,0,255";
				} else if (y % mod == 5) {
					colour = "255,255,0";
				} else if (y % mod == 6) {
					colour = "255,125,0";
				} else if (y % mod == 7) {
					colour = "255,0,125";
				} else if (y % mod == 8) {
					colour = "0,255,125";
				} else if (y % mod == 9) {
					colour = "125,255,0";
				} else if (y % mod == 10) {
					colour = "125,0,255";
				} else if (y % mod == 11) {
					colour = "0,125,255";
				}

				double ynew = (result-(t.starty+t.height));
				buffprint.println("<rect x=\"" + (offset+(t.startx)) + "\" y=\"" + (offset+(ynew)) 
						+ "\" width=\"" + (t.width) + "\" height=\"" + (t.height) + "\"");
				buffprint.println("style=\"fill:rgb(" + colour + ");");
				buffprint.println("stroke-width:0.05;stroke:rgb(0,0,0)\"/>");

				buffprint.println();
			}
			for (int y = 0; y < pieceorder.size(); y++) {
				pieceCoordinate t = pieceorder.elementAt(y);
				double ynew = (result-(t.starty+t.height));
				buffprint.println(
						"<text x=\""+(offset+(t.startx))+"\" y=\""+(offset+(ynew)+2) +"\" font-family=\"Verdana\" font-size=\"2\" fill=\"black\" > " +
						y +
				" </text>");
			}
			buffprint.println("</svg>");
			buffprint.close();
			f.close();
		} catch (IOException a) {
			System.err.println(a.getMessage());
			System.exit(0);
		} // end catch*/


	}


}
